﻿using System;
using System.Web;
using System.Web.Mvc;

namespace ML.Web.Controllers
{
    /// <summary>
    /// 特性，限制当前功能只允许使用AJax请求来访问
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class AjaxOnlyAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Result = new ContentResult
                {
                    Content = "只允许Ajax请求"
                };
            }
        }
    }
}